package com.hyts.xmlparser.convert.global;

import com.hyts.xmlparser.config.XmlParseConfig;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.xmlparser.convert
 * author:Libo/Alex
 * create-date:2019-07-18 13:23
 * email:liboware@gmail.com
 * description:此类主要用于:
 */
@NoArgsConstructor
@AllArgsConstructor
public class DateConverter implements Converter {


    @Getter
    private String dateFormatPattern;

    /**
     * 转换编译替换编排
     * @param source
     * @param writer
     * @param context
     */
    @Override
    public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
        if (null == dateFormatPattern) {
            dateFormatPattern = XmlParseConfig.DEFAULT_XML_DATE_FORMAT;
        }

    }

    @Override
    public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
        return null;
    }

    @Override
    public boolean canConvert(Class type) {
        return Date.class.isAssignableFrom(type);
    }
}
